package com.dmz.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dmz.workflow.base.BaseServiceImpl;
import com.dmz.workflow.dao.WorkflowFormDataMapper;
import com.dmz.workflow.service.WorkflowFormDataService;
import com.dmz.workflow.entity.FormData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class WorkflowFormDataServiceImpl extends BaseServiceImpl<WorkflowFormDataMapper, FormData> implements WorkflowFormDataService {

    @Autowired
    private WorkflowFormDataMapper workflowFormDataMapper;

    private LambdaQueryWrapper<FormData> lambdaQueryWrapper;

    private LambdaUpdateWrapper<FormData> lambdaUpdateWrapper;

    @Override
    public FormData selectFormDataByProcessInstanceId(String processInstanceId) {
        lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FormData::getProcessInstanceId, processInstanceId);
        return workflowFormDataMapper.selectOne(lambdaQueryWrapper);
    }

    @Override
    public boolean updateFormDataByProcessInstanceId(String processInstanceId, String formDataStr) {
        lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(FormData::getProcessInstanceId, processInstanceId);
        FormData formData = new FormData();
        formData.setFormData(formDataStr);
        return this.update(formData, lambdaUpdateWrapper);
    }

}
